package com.dubbo.comsumer;

import com.dubbo.bean.User;
import com.dubbo.protocol.http.HttpClient;
import com.dubbo.protocol.netty.NettyRpcClient;
import com.dubbo.protocol.socket.SocketClient;
import com.dubbo.register.RemoteRegister;
import com.dubbo.service.UserService;


import java.net.URL;
import java.util.List;

public class Comsumer
{
    public static void main(String[] args) throws Exception
    {
        //通过网络注册器，获取到url对象
        System.out.println("key:"+UserService.class.getName());
        URL url = (URL) RemoteRegister.getInstance().get(UserService.class.getName());
        System.out.println("通过网络注册中心获取到URL对象：" + url);
        //指定 通讯协议
//        UserService userService = RpcClientProxy.newInstance(UserService.class, new HttpClient());
//        UserService userService = RpcClientProxy.newInstance(UserService.class, new SocketClient());
        UserService userService = RpcClientProxy.newInstance(url, UserService.class, new HttpClient());
        List<User> list = userService.findList();



        for(User user : list)
        {
            System.out.println(user);
        }
    }
}
